<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
     <title>机构列表</title>
    
     <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
  	<script type="text/javascript">
  	<!--
  	$(document).ready(function(){
  		//alert("ok");
  		$(".showDeps").click(function(){
  			//alert($(this).text());
  			if($(this).text() == 0)
  				return;
  			$(this).next().toggle();
  			//for(var i=0; i<$(this).text(); i++)
  		//		alert();
  		});
  	});
  	//-->
    </script>
    <link href="images/skin.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
	body{
		margin:0;
		padding:0;
	}
	#top{
		width: 100%;
		height: 63px;
	}
	#left{
		position: absolute;
		left: 0;
		top: 65px;
		width:185px;

	}
	#right{
		position: absolute;
		left: 186px;
		top: 65px;
		width: 1100px;
	}
	</style>
  </head>
  
  
  <body>
  
	
	<div id="top"><jsp:include page="/WEB-INF/page/top.jsp"></jsp:include></div>
	<div id="left"><jsp:include page="/WEB-INF/page/lef.jsp"></jsp:include></div>
	<div id="right">
	
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td valign="top" background="images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
      <tr>
        <td height="31"><div class="titlebt">机构列表</div></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9"><table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td colspan="2" valign="top">&nbsp;</td>
        <td>&nbsp;</td>
        <td valign="top">&nbsp;</td>
      </tr>
      <tr>
        <td colspan="2" valign="top"><span class="left_bt"></span><br/>

			<table border="1" width="550px">
  <tr><th style="text-align:center">级别</th><th style="text-align:center">机构名</th><th style="text-align:center">管理员</th><th style="text-align:center">下级机构数</th><th style="text-align:center">部门数</th><th>&nbsp;</th></tr>
    <c:forEach var="ins" items="${institutions}">
    <tr>
    	<td style="text-align:center">${ins.level }</a></td>
    	<td style="text-align:center">${ins.name }</td>
    	<td style="text-align:center">${ins.adminId }</td>
    	<td style="text-align:center">
    		<c:if test="${ins.institutions != null }">
    			${fn:length(ins.institutions) }
    		</c:if>
    	</td>
    	<td style="text-align:center; width:150px;" >
    		<c:if test="${ins.departments != null }">
    			<a class="showDeps" href="javascript:void(0);"  value="${ins.id }">${fn:length(ins.departments) }</a>
    			  <div id="depsTable${ins.id }" idval="${ins.id }" style="display:none; position: absolute; left:580px;">
    			  <table border="1">
    			  <tr  style="text-align:center"><th>部门名</th><th>成员数</th><th>状态</th></tr>
	    			<c:forEach var="dep" items="${ins.departments}">
	    				<tr  style="text-align:center">
	    					<td>${dep.name }</td>
	    					<td>${fn:length(dep.users) }</td>
	    					<td>
	    						<c:choose>
	    							<c:when test="${dep.state == 1 }">
	    								活动
	    							</c:when>
	    							<c:otherwise>
	    								锁定
	    							</c:otherwise>
	    						</c:choose>
							</td>
	    				</tr>
	    			</c:forEach>
	    		</table>
    			</div>
    		</c:if>
    	</td>
    	<td style="text-align:center">
    	<a href="goUpdateInstitution.action?id=${ins.id }" target="_self">修改</a>
	 	<c:choose>
	    	<c:when test="${ins.state == 1 }">
	    		<a href="lockInstitution.action?id=${ins.id }" target="_self">锁定</a>
	    	</c:when>
	    	<c:when test="${ins.state == 2 }">
	    		<a href="unlockInstitution.action?id=${ins.id }" target="_self">解锁</a>
	    	</c:when>
    	</c:choose>
    	<a href="deleteInstitution.action?id=${ins.id }" target="_self">删除</a>
    	</td>
    </tr>
    </c:forEach>
    </table>
    <a href="goAddInstitution.action" target="_self">添加机构</a>
    <a href="goMain.action" target="_self">返回</a>
        </td>
          </tr>
	</div>
  
  </body>
</html>
